package algos;

public class LaplaceLaw extends EstimationFunction {

    private final double nTrainsPlusBins;

    public LaplaceLaw(NGramModel model) {
        super(model);
        nTrainsPlusBins = model.getNTrains() + model.getBins().doubleValue();
    }

    @Override
    public double p(int wordIndex) {
        if (nTrainsPlusBins == 0.){
            return 0.;
        }
        return (model.predict(wordIndex) + 1.) / nTrainsPlusBins;
    }
}
